home *** CD-ROM | disk | FTP | other *** search
- Path: news.bridge.net!news
- From: michael@bridge.net
- Newsgroups: comp.lang.c
- Subject: Re: How do I read a random I/O file into a structure ?
- Date: Thu, 21 Mar 1996 23:09:05 GMT
- Organization: BridgenetLC - 305.374.3031 - 100 S. Biscayne Blvd, Miami
- Message-ID: <4isnjf$e69@news.bridge.net>
- References: <4iskkm$guk@cti01.citenet.net> <4isl5t$guk@cti01.citenet.net>
- Reply-To: michael@bridge.net
- NNTP-Posting-Host: ppp-mia1-43.bridge.net
- X-Newsreader: Forte Free Agent 1.0.82
-
- kabir@citenet.net (larry mintz) wrote:
-
-
- >I have the following data in a file called log.dat.It represents the login/out
- >times of people on a network: The fields are
- > NAME LOGIN_TIME LOGOUT_TIME PORT
- >with the following data:
- > kthomas 3:30:45 4:00:00 23
- > urstupid 5:12:12 67
- > iamsmart 12:34:11 13:23:11 90
- > kthomas 14:23:11 15:12:45 23
- > urstupid 5:30:12 6:00:00 25
-
- >The structure I am using is
- > struct xx{ char NAME[10];
- > char LOGIN_TIME[10];
- > char LOGOUT_TIME[10];
- > unsigned PORT:5;
- > };
- >struct xx LOGTABLE[10];
-
- >Question: How do I load log.dat into the struct LOGTABLE[10] so all the data
- >is in the proper fields?
- >kabir.
-
-
- Hi Kabir,
-
- What works well is the fread() function. For example:
- fread(LOGTABLE, sizeof(xx), 10, FILE * stream);
- the last one is a file pointer stream such as that returned by
- fopen().
-
- What you have done is declared an array of 10 structures of the type
- xx. if you don't know how many you need you could set up the strcture
- to only hold one structure at a time, put everything in a while loop
- that says
- fread();
- while(FILE * ! EOF)
- {
- printf();
- fread();
- }
-
- Let me know if this helps. it is easier to email me since I don't
- always check the newsgroups.
-
- michael@bridge.net
-
-
-